/** \file TA_t.cc 
 * Test definitions for Stochastic functions.
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Stochastic_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "Stochastic.hpp"
#include <vector>
#include "Stock.hpp"
#include "SecurityAdaptor.hpp"
#include "TestHarness.hh"

using namespace std;
using namespace TC;



namespace {

  const unsigned DataSize = 56;

  const double stochastic_hi[DataSize] = {
    34.3750, 34.7500, 34.2188, 33.8281, 33.4375, 33.4688, 34.3750,
    34.7188, 34.6250, 34.9219, 34.9531, 35.0625, 34.7812, 34.3438,
    34.5938, 34.3125, 34.2500, 34.1875, 33.7812, 33.8125, 33.9688,
    33.8750, 34.0156, 33.5312, 33.4375, 33.6875, 33.9375, 33.6250,
    33.6562, 34.0625, 34.0625, 34.4219, 34.7656, 34.9062, 34.6875,
    34.4688, 34.3438, 34.0000, 34.1562, 33.6562, 33.8125, 34.8086,
    34.6250, 34.3125, 34.3125, 34.0625, 33.7500, 33.7656, 32.9062,
    32.8750, 33.5625, 33.7344, 33.6562, 33.3750, 33.0000, 33.1250 };

  const double stochastic_lo[DataSize] = {
    33.5312, 33.9062, 33.6875, 33.2500, 33.0000, 32.9375, 33.2500,
    34.0469, 33.9375, 34.0625, 34.4375, 34.5938, 33.7656, 33.2188,
    33.9062, 32.6562, 32.7500, 33.1562, 32.8594, 33.0000, 33.2969,
    33.2812, 33.0312, 33.0156, 32.9062, 33.2188, 33.0625, 32.8438,
    33.1875, 33.3438, 33.5625, 33.6562, 34.0625, 34.5312, 34.0625,
    34.1406, 33.8438, 33.7188, 33.0625, 32.5938, 31.8750, 33.8281,
    33.8438, 33.0000, 33.3125, 32.1562, 30.8750, 32.5312, 32.1250,
    32.4062, 32.8281, 33.2969, 33.1250, 32.9375, 32.4688, 32.4375 };

  const double stochastic_cls[DataSize] = {
    34.3125, 34.1250, 33.7500, 33.6406, 33.0156, 33.0469, 34.2969,
    34.1406, 34.5469, 34.3281, 34.8281, 34.8750, 33.7812, 34.2031,
    34.4844, 32.6719, 34.0938, 33.2969, 33.0625, 33.7969, 33.3281,
    33.8750, 33.1094, 33.1875, 33.3438, 33.6250, 33.0781, 33.4688,
    33.2969, 33.7344, 33.7812, 34.1406, 34.7500, 34.7344, 34.1250,
    34.1875, 34.1719, 33.9375, 33.4766, 33.0625, 33.1562, 34.6250,
    33.9219, 33.9062, 33.8438, 32.1875, 33.3438, 32.7812, 32.1562,
    32.5000, 33.5312, 33.5625, 33.3906, 33.0156, 32.8906, 32.5469 };

  const double stochastic_kpct[DataSize] = {
    00.0000, 00.0000, 00.0000, 00.0000, 00.000, 00.00000, 29.6880, 
    53.1056, 83.4363, 75.7725, 83.7131, 81.1678, 61.3624, 45.4192, 
    45.4527, 37.1794, 42.6494, 32.3703, 41.4086, 39.5499, 41.7185, 
    60.9758, 46.2741, 41.5183, 26.6701, 41.5502, 39.9105, 45.7570, 
    37.9156, 57.7992, 64.6003, 77.8185, 86.7837, 90.0670, 78.3997, 
    59.7772, 38.8912, 30.8046, 24.7987, 23.4992, 36.2552, 61.8339, 
    72.9139, 77.5850, 68.7085, 47.3179, 47.8674, 44.7799, 53.2348, 
    47.8251, 58.4556, 74.0889, 87.2765, 72.3538, 54.6441, 29.3161 };

  const double stochastic_dpct[DataSize] = {
    00.0000, 00.0000, 00.0000, 00.0000, 00.000, 00.00000, 00.0000,
    00.0000, 55.4100, 70.7715, 80.9740, 80.2178, 75.4144, 62.6498, 
    50.7448, 42.6838, 41.7605, 37.3997, 38.8094, 37.7762, 40.8923, 
    47.4147, 49.6562, 49.5894, 38.1542, 36.5796, 36.0436, 42.4059, 
    41.1943, 47.1573, 53.4384, 66.7393, 76.4008, 84.8897, 85.0835, 
    76.0813, 59.0227, 43.1577, 31.4982, 26.3675, 28.1844, 40.5294, 
    57.0010, 70.7776, 73.0691, 64.5372, 54.6313, 46.6551, 48.6274, 
    48.6133, 53.1718, 60.1232, 73.2737, 77.9064, 71.4248, 52.1046 };


}


TEST(StochasticTest, Base)
{
  //TC_LOG_FUNC(Stochastic_test);

     vector<StockDef> data(DataSize);
     vector<double> kvals, dvals;
     unsigned i;
     
     for(i=0; i<DataSize; ++i) {
       data.at(i).setHi(static_cast<TAfp_t>(stochastic_hi[i]));
       data.at(i).setLo(static_cast<TAfp_t>(stochastic_lo[i]));
       data.at(i).setCls(static_cast<TAfp_t>(stochastic_cls[i]));
     }


     Stochastic(data.begin(), data.end(),
                back_inserter(kvals),
                back_inserter(dvals),
                5, 3, 3,
                SecurityAdaptor<StockDef>());

     TC_TEST(kvals.size()==DataSize);
     for(i=0; i<DataSize; ++i) {
       TC_LOG_DEBUG("Checking kvals[" << i << "]=" << kvals[i] <<
                    " expected=" << stochastic_kpct[i]);
       if(stochastic_kpct[i])
         TC_TESTFPC(stochastic_kpct[i], kvals[i], 0.15);
     }
     PrintElements(kvals, "%K values");

     TC_TEST(dvals.size()==DataSize);
     for(i=0; i<DataSize; ++i) {
       TC_LOG_DEBUG("Checking dvals[" << i << "]=" << dvals[i] <<
                    " expected=" << stochastic_dpct[i]);
       if(stochastic_dpct[i])
         TC_TESTFPC(stochastic_dpct[i], dvals[i], 0.15);
     }
     PrintElements(dvals, "%D values");

}


  



